package chapter4;
import java.util.Scanner;
/****************************************************************
 * Author：icynlau
 * Description:  估算面积
 * 四个城市的坐标为：(分别为A,B,C,D城市 ，这四个城市组成 三角形ABC 和 三角形ABD)
        double x1 = 35.2270869;
        double y1 = -80.8431267;
      	double x2 = 32.0835407;
        double y2 = -81.0998342;
        double x3 = 33.7489954;
        double y3 = -84.3879824;
        double x4 = 28.5383355;
        double y4 = -81.3792365;
 * 
 * Date:2021/4/2
 * ***************************************************************
 */
public class exc4_3 {
	private static double distance(double x1,double y1,double x2,double y2) {
		final double R=6371.01;
		double d=R*Math.acos(Math.sin(Math.toRadians(x1))*Math.sin(Math.toRadians(x2))
				+Math.cos(Math.toRadians(x1))*Math.cos(Math.toRadians(x2))*Math.cos(Math.toRadians(y1-y2)));
		return d;
	}
	
	public static void main(String[] args) {
		
        double x1 = 35.2270869;
        double y1 = -80.8431267;
      	double x2 = 32.0835407;
        double y2 = -81.0998342;
        double x3 = 33.7489954;
        double y3 = -84.3879824;
        double x4 = 28.5383355;
        double y4 = -81.3792365;
        //求三角形的边AB 的长度 lAB 以下同理
        double lAB=distance(x1,y1,x2,y2);
        double lAC=distance(x1,y1,x3,y3);
        double lAD=distance(x1,y1,x4,y4);
        double lBD=distance(x2,y2,x4,y4);
        double lBC=distance(x2,y2,x3,y3);
        
        //利用exc2_19的求三角形面积的公式
        double s1=(lAB+lAC+lBC)/2;
        double s2=(lAB+lAD+lBD)/2;
        
        System.out.printf("The area is about %.10f km^2", (Math.sqrt(s1*(s1-lAB)*(s1-lAC)*(s1-lBC))+Math.sqrt(s2*(s2-lAB)*(s2-lAD)*(s2-lBD))));
		
	}
	

}
